package test;
import java.sql.*;
public class mysqy {

    /*数据库驱动*/
    static final String JDBC_DRIVER="com.mysql.cj.jdbc.Driver";
    /*数据库url*/
    static final String DB_URL="jdbc:mysql://localhost:3306/student_gui";

    //数据库名与密码
    static final String user="root";
    static final String pass="111111";

    public static void main(String[] args){
        Connection conn=null;
        Statement stmt=null;

        try {
            //注册驱动
            Class.forName(JDBC_DRIVER);
            System.out.println("-----连接数据库----");
            //打开连接
            conn= DriverManager.getConnection(DB_URL,user,pass);
            //执行查询user表数据
            stmt=conn.createStatement();
            String sql;
            sql="select pwd from manager where user_name=?";
            ResultSet rs=stmt.executeQuery(sql);
            //数据输出
            while(rs.next()){
                int id=rs.getInt("id" );
                String name=rs.getString("user_name");
                String pass=rs.getString("password");
                System.out.println("ID="+id);
                System.out.println("用户名="+name);
                System.out.println("密码="+pass);
                System.out.println();

            }
            //完成并关闭数据库
            rs.close();
            stmt.close();
            conn.close();
            System.out.println("查询结束关闭数据库");

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }catch (SQLException se){
            se.printStackTrace();
        }
    }
}
